package ext.tianma.bom.service;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping({ "/show" })
public class ShowController {

	@RequestMapping(value = "/showDrawing", method = { RequestMethod.POST, RequestMethod.GET })
	public void newestPartMessage(@RequestParam(value = "number", required = true) String number,
			@RequestParam(value = "numType", required = true) String numType,
			@RequestParam(value = "name", required = true) String name, HttpServletResponse response) throws Exception {
		boolean enforce = wt.session.SessionServerHelper.manager.setAccessEnforced(false);
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		try {
			String result = ShowService.getShowData(number.trim(), numType.trim(), name.trim());
			out.print(result);
		} catch (Throwable e) {
			e.printStackTrace();
		} 
		finally {
			wt.session.SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}

	/**
	 * 查看当前用户是否有当前文档的下载权限
	 * 
	 * @param number
	 * @throws Exception
	 */
	@RequestMapping(value = "/queryPermissions", method = { RequestMethod.POST, RequestMethod.GET })
	public void queryPermissions(@RequestParam(value = "docNumber", required = true) String docNumber,
			HttpServletResponse response) throws Exception {
		PrintWriter out = response.getWriter();
		response.setContentType("text/html;charset=UTF-8");// 返回文本值
		try {
			String result = DrawingHelp.queryPermissions(docNumber);// 查看当前用户是否有当前文档的下载权限
			out.print(result);
		} catch (Throwable e) {
			e.printStackTrace();
		}
	}

}
